package com.johnlee.sentinel_quick_start.controller;

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController_02 {
    // availability
    @GetMapping("helloDynamic")
    public String helloDynamic() {
        // 使用限流规则
        try(Entry entry = SphU.entry("HelloDynamic")){ // 限流入口
            return "Hello Sentinel Dynamic";  // 保护的资源
        } catch (BlockException e) {
            e.printStackTrace();
            return "busy"; // 被限流或者被降级的操作处理
        }
    }
}
